package com.example.appjetpackcompose

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.compose.ui.viewinterop.AndroidView
import androidx.compose.ui.viewinterop.AndroidViewBinding
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.appjetpackcompose.databinding.FragmentTest3Binding
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.ClassicsHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.scwang.smart.refresh.layout.api.RefreshLayout
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener
import com.scwang.smart.refresh.layout.listener.OnRefreshListener


class TestActivity4Fragment3: Fragment() {

    val TAG=TestActivity4Fragment3::class.java.simpleName

    companion object{
        fun newInstance(): TestActivity4Fragment3{
            val args = Bundle()
            val fragment = TestActivity4Fragment3()
            fragment.arguments = args
            return fragment
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
//        return super.onCreateView(inflater, container, savedInstanceState)
        return ComposeView(requireContext()).apply {
            setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
            setContent {
                MaterialTheme{
                    AndroidViewBindingExample(requireContext())
                }
            }
        }
    }
}

@Composable
fun AndroidViewBindingExample(context:Context) {
    AndroidViewBinding(FragmentTest3Binding::inflate) {
        fragTest3Rv.layoutManager=LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false)
        fragTest3Refreshlayout.setRefreshHeader(ClassicsHeader(context))
        fragTest3Refreshlayout.setRefreshFooter(ClassicsFooter(context))
        fragTest3Refreshlayout.setOnRefreshListener {
            it.finishRefresh(2000)
        }
        fragTest3Refreshlayout.setOnLoadMoreListener{
            it.finishLoadMore(2000)
        }

    }
}